package org.crazyit.activiti_d3._2_AddUser;

import org.activiti.engine.IdentityService;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.identity.User;

import java.util.UUID;

public class AddUser {

    public static void main(String[] args) {

        //1. 创建流程引擎
        ProcessEngine engine = ProcessEngines.getDefaultProcessEngine();

        //2. 得到身份服务组件实例
        IdentityService identityService = engine.getIdentityService();

        //3. 使用newUser 方法创建User 实例
        String id = UUID.randomUUID().toString();
        User user = identityService.newUser(id);

        //4. 设置用户的各个属性
        user.setFirstName("Angus");
        user.setLastName("Young");
        user.setEmail("yangenxiong@163.com");
        user.setPassword("abc");

        //5. 使用saveUser 方法保存用户信息
        identityService.saveUser(user);

        //6. 根据id 查询
        User user1 = identityService.createUserQuery().userId(id).singleResult();
        System.out.println(user1.getEmail());

    }

}
